﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TLL.Finance.Currencys
{
    public class Currency
    {
        #region Varible

            private double buy = 0;
            private double sale = 0;
            private CurrencyType type = default(CurrencyType);
            private CurrencyCountry country = default(CurrencyCountry);
            private double averageBuyRate = 0;
            private double averageSaleRate = 0;
            private double minRate = 0;
            private double maxRate = 0;

        #endregion

        #region Properties

            public CurrencyType Type { get { return this.type; } }
            public CurrencyCountry Country { get { return this.country; } }
            public double AverageBuyRate { get { return this.averageBuyRate; } set { this.averageBuyRate = value; } }
            public double AverageSaleRate { get { return this.averageSaleRate; } set { this.averageSaleRate = value; } }
            public double MinRate { get { return this.minRate; } set { this.minRate = value; } }
            public double MaxRate { get { return this.maxRate; } set { this.maxRate = value; } }
            public double Buy { get { return this.buy; } }
            public double Sale { get { return this.sale; } }

        #endregion

        public Currency(CurrencyType type, CurrencyCountry country, double buy, double sale, double avarageBuyRate, double avarageSaleRate, double minRate, double maxRate)
        {
            this.buy = buy;
            this.sale = sale;
            this.type = type;
            this.averageBuyRate = avarageBuyRate;
            this.averageSaleRate = avarageSaleRate;
            this.maxRate = maxRate;
            this.minRate = minRate;
            this.country = country;
        }
        public Currency(CurrencyType type, double buy, double sale)
        {
            this.buy = buy;
            this.sale = sale;
            this.type = type;
        }
        public Currency(CurrencyType type, CurrencyCountry country, double buy, double sale)
        {
            this.buy = buy;
            this.sale = sale;
            this.type = type;
            this.country = country;
        }
        public Currency(Invoice invoice)
        {
            this.buy = invoice.Value;
            this.type = invoice.Type;
        }

        public static string Formated(Currency item, CurrencyFormatedType type = CurrencyFormatedType.Default)
        {
            try
            {
                switch (type)
                {
                    case CurrencyFormatedType.SaleBuy:
                        return item.Sale.ToString("0.00") + "/" + item.Buy.ToString("0.00");
                    default:
                        return item.Buy.ToString("0.00") + "/" + item.Sale.ToString("0.00");
                }
            }
            catch { return string.Empty; }
        }
    }
}
